// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ActorRuntimeManager
{
    public partial class ConnectionInformationForm : Form
    {
        public string ConnectionString { get; set; }
        public ConnectionMode ConnectionMode { get; set; }
        public bool OKSelected { get; set; }
        public string AccountName { get; set; }
        public string ContainerName { get; set; }
        public string AccountKey { get; set; }

        public ConnectionInformationForm(ConnectionMode currentConnectionMode, string currentConnectionString,
                                        string accountName, string containerName, string accountKey)
        {
            InitializeComponent();
            ConnectionMode = currentConnectionMode;
            ConnectionString = currentConnectionString;
            AccountName = accountName;
            AccountKey = accountKey;
            ContainerName = containerName;

            OKSelected = false;

            textBoxAccountName.Text = AccountName;
            textBoxAccountKey.Text = AccountKey;
            textBoxContainerName.Text = ContainerName;

            if (ConnectionMode == ActorRuntimeManager.ConnectionMode.Local)
            {
                this.radioButtonLocal.Select();
                this.textBoxAccountName.Enabled = false;
                this.textBoxContainerName.Enabled = false;
                this.textBoxAccountKey.Enabled = false;
            }
            else this.radioButtonCloud.Select();

            this.textBoxConnectionString.Text = currentConnectionString;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            ConnectionString = textBoxConnectionString.Text;
            ConnectionMode = (radioButtonCloud.Checked) ? ConnectionMode.Cloud : ConnectionMode.Local;
            AccountName = textBoxAccountName.Text;
            ContainerName = textBoxContainerName.Text;
            AccountKey = textBoxAccountKey.Text;
            OKSelected = true;
            Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void radioButtonLocal_CheckedChanged(object sender, EventArgs e)
        {
            if (this.radioButtonLocal.Checked)
            {
                this.textBoxAccountName.Enabled = false;
                this.textBoxContainerName.Enabled = false;
                this.textBoxAccountKey.Enabled = false;
            }
            else
            {
                this.textBoxAccountName.Enabled = true;
                this.textBoxContainerName.Enabled = true;
                this.textBoxAccountKey.Enabled = true;
            }
        }
    }
}
